﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinAutomator.Library.InOut;

namespace WinAutomator.Library
{
    public class WAWorkflow
    {
        IProcess _root;
        IProcess _current;

        public void SetRoot(IProcess root)
        {
            _root = root;
            _current = root;
        }

        public void Start()
        {
            while (_current != null)
            {
                //Execute process
                IConnector con = executeProcess(_current);
                if ((con != null) && (con.HasChild))
                {
                    //Transfert data to next node
                    con.Execute();
                    // set next node as current
                    _current = con.GetLinkConnector().Process;
                }
                else
                {
                    _current = null;
                }
            }
        }


        private IConnector executeProcess(IProcess current)
        {
            return current.Execute();
        }
    }
}
